from typing import List, Dict, Any
# 将输入数据为多模态向量化处理的数据格式

def convert_multimodal_input(data: Dict[str, Any]) -> List[Dict[str, Any]]:
    # 这里直接使用字段，不再进行 json.loads()
    speech_rate_list = data["speechRate"]
    audio_emotion_list = data["audioEmotion"]
    facial_actions_list = data["facialActions"]
    body_movements_list = data["bodyMovements"]
    micro_expression_list = data["microExpression"]
    stress_list = data["stress"]

    num_rounds = len(speech_rate_list)
    result = []

    for i in range(num_rounds):
        # 获取面部动作和身体动作
        face_actions = facial_actions_list[i] if i < len(facial_actions_list) else {}
        body_actions = body_movements_list[i] if i < len(body_movements_list) else {}
        
        # 创建扁平结构的数据条目
        entry = {
            "text": speech_rate_list[i]["text"],
            "audio_emotion": audio_emotion_list[i] if i < len(audio_emotion_list) else "",
            "stress": float(stress_list[i]) if i < len(stress_list) else 0.0,
            "expression_seq": micro_expression_list[i] if i < len(micro_expression_list) else "",
            "speech_rate": speech_rate_list[i]["speed"],
            # 展平面部动作字段
            "eyeBlink": face_actions.get("eyeBlink", 0),
            "mouthPuff": face_actions.get("mouthPuff", 0),
            "eyeUpLeft": face_actions.get("eyeUpLeft", 0),
            "eyeUpRight": face_actions.get("eyeUpRight", 0),
            # 展平身体动作字段
            "earTouch": body_actions.get("earTouch", 0),
            "noseTouch": body_actions.get("noseTouch", 0),
        }
        result.append(entry)

    return result

